package com.acheli.utils.math.angle;

public class Angle implements AbstractAngle{  //普通角
    private double angleNumber = 0F;
    private AbstractAngle upperLimit;
    private AbstractAngle lowerLimit;

    public Angle(double angleNumber){
        this.angleNumber = angleNumber;
    }

    public Angle(double angleNumber, AbstractAngle upperLimit, AbstractAngle lowerLimit){
        this.angleNumber = angleNumber;
        this.upperLimit = upperLimit;
        this.lowerLimit = lowerLimit;
    }

    @Override
    public void setUpperLimit(AbstractAngle upperLimit) {
        this.upperLimit = upperLimit;
    }

    @Override
    public void setLowerLimit(AbstractAngle lowerLimit) {
        this.lowerLimit = lowerLimit;
    }

    @Override
    public AbstractAngle getUpperLimit() {
        return this.upperLimit;
    }

    @Override
    public AbstractAngle getLowerLimit() {
        return this.lowerLimit;
    }

    public boolean upperThanLimit(AbstractAngle angle) {
        if (this.upperLimit != null){
            return angle.getAngleNum() > this.upperLimit.getAngleNum();
        }
        return false;
    }

    public boolean lowerThanLimit(AbstractAngle angle) {
        if (this.lowerLimit != null){
            return angle.getAngleNum() < this.lowerLimit.getAngleNum();
        }
        return false;
    }

    @Override
    public void setAngle(AbstractAngle angle) {
        if (lowerThanLimit(angle) || upperThanLimit(angle)){
            return;
        }
        this.angleNumber = angle.getAngleNum();
    }

    public void setAngleNum(double angleNum) {
        Angle angle = new Angle(angleNum);
        if (lowerThanLimit(angle) || upperThanLimit(angle)){
            return;
        }
        this.angleNumber = angleNum;
    }
    public double getAngleNum(){
        return this.angleNumber;
    }
    public void setArcAngleNum(double arcAngleNum) {
        ArcAngle arcAngle = new ArcAngle(arcAngleNum);
        if (lowerThanLimit(arcAngle) || upperThanLimit(arcAngle)){
            return;
        }
        this.angleNumber = arcAngleNum*180 /Math.PI;
    }
    public double getArcAngleNum(){
        return this.angleNumber/180 * Math.PI;
    }

    @Override
    public void add(AbstractAngle otherAngle) {
        angleNumber += otherAngle.getAngleNum();
    }
}
